package	com.sdry.web.controller.tdd.sale;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sdry.model.tdd.sale.SaleExpenseAccount;
import com.sdry.model.zc.ZcSysUserEntity;
import com.sdry.service.tdd.sale.SaleExpenseAccountService;
import com.sdry.utils.DateUtil;
import com.sdry.utils.ResponseUtil;
import com.sdry.web.controller.tdd.emailRecord.EmailRecordController;
/**
 *
 *@ClassName: SaleExpenseAccountController
 *@Description: 费用科目
 *@Author tdd
 *@Date 2019-09-25 11:22:39
 *@version 1.0
*/
@Controller
@RequestMapping("/saleExpenseAccount")
public class SaleExpenseAccountController{
	@Resource SaleExpenseAccountService saleExpenseAccountService;
	//声明一个Logger
	private final static Logger logger = LoggerFactory.getLogger(EmailRecordController.class);
	/** 
	 * 进入页面
	 * @param model
	 * @return 页面路径
	*/
	@RequestMapping("/page")
	public String pageSaleExpenseAccount (Model model) {
		return "/td/sale/saleExpenseAccount";
	}
	/** 
	 * 根据主键id查询实体
	 * @param id 主键id
	 * @return 实体
	*/
	@RequestMapping("/queryById")
	@ResponseBody
	public SaleExpenseAccount queryById(Long id) {
		SaleExpenseAccount param = saleExpenseAccountService.queryById(id);
		return param;
	}
	/** 
	 * 条件查询所有
	 * @param param 实体条件
	 * @return 实体集合
	*/
	@RequestMapping("/queryAllByMution")
	@ResponseBody
	public List<SaleExpenseAccount> queryAllByMution(SaleExpenseAccount param) {
		List<SaleExpenseAccount> list = saleExpenseAccountService.queryAllByMution(param);
		return list;
	}
	/** 
	 * 条件分页查询
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/list")
	public void list(SaleExpenseAccount param,HttpServletResponse response) throws Exception{
		/*
		 * 条件分页查询内容
		 */
		List<SaleExpenseAccount> list = saleExpenseAccountService.findPageByMution(param);
		/*
		 * 条件查询总条数
		 */
		Integer total = saleExpenseAccountService.selectCountByMution(param);
		/*
		 * 转为json数据传至页面
		 */
		//创建result
		JSONObject jsonObject = new JSONObject();
		//添加入jsonObject
		jsonObject.put("code", 0);
		jsonObject.put("rows", list);
		jsonObject.put("total", total);
		ResponseUtil.write(response, jsonObject);
	}
	/** 
	 * 插入返回id
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/insert")
	public void insert(SaleExpenseAccount param,HttpSession httpSession,HttpServletResponse response) throws Exception{
		param.setEisTrue("0");
		//获取当前操作人
		ZcSysUserEntity su = (ZcSysUserEntity)httpSession.getAttribute("user");
		param.setEcreateMan(su.getUserName());
		param.setEcreateTime(DateUtil.dateFormat3());
		Long id = saleExpenseAccountService.insert(param);
		ResponseUtil.write(response,id);
	}
	/** 
	 * 根据主键更新 返回影响行数
	 * @param param 实体条件
	 * @param response
	 * @throws Exception
	*/
	@RequestMapping("/update")
	public void update(SaleExpenseAccount param,HttpServletResponse response) throws Exception{
		Integer count = saleExpenseAccountService.update(param);
		ResponseUtil.write(response,count);
	}
	/** 
	 * 根据主键拼接的字符串删除返回影响行数
	 * @param ids 主键拼接的字符串
	 * @return 影响行数
	*/
	@RequestMapping("/delete")
	public void delete(String ids,HttpServletResponse response) throws Exception{
		ids=ids.replace("'",""); 
		Integer count = saleExpenseAccountService.delete(ids);
		ResponseUtil.write(response,count);
	}
	/** 
	 * 根据主键拼接的字符串批量修改状态返回影响行数
	 * @param ids 主键拼接的字符串
	 * @param eisTrue 状态
	 * @return 影响行数
	 */
	@RequestMapping("/updateEisTrueByIds")
	public void updateEisTrueByIds(String ids,String eisTrue,HttpServletResponse response) throws Exception{
		ids=ids.replace("'",""); 
		Integer count = saleExpenseAccountService.updateEisTrueByIds(ids, eisTrue);
		ResponseUtil.write(response,count);
	}
}
